package main

import (
	"fmt"
	"strconv"
	"sync"
)

//使⽤两个  goroutine 交替打印序列，⼀个  goroutine 打印数字， 另外⼀
//个  goroutine 打印字⺟

var chNumber = make(chan int)
var chLetter = make(chan int)
var str = ""
var wg = sync.WaitGroup{}

func main() {
	wg.Add(1)
	go num()
	go letter()

	chNumber <- 0
	wg.Wait()
	fmt.Println(str)

}

func num() {
	i := 0
	for {

		select {
		case num := <-chNumber:
			i++
			str += strconv.Itoa(i)
			chLetter <- 1
			fmt.Println("ssss====", num)
		default:
			break
		}
	}
}

func letter() {

	strABC := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	i := 0
	for {

		select {
		case <-chLetter:
			str += strABC[i : i+1]
			i++
			chNumber <- i
			if i == 20 {
				wg.Done()
				return
			}
		default:
			break
		}
	}
}

//func astr(ch chan string){
//
//	i := 0
//str := ""
//for{
//	i++
//	if <-chFlag==true {
//		return
//	}
//str = <-ch
//ch<-(str +  strconv.Itoa(i))
//}
//}

//func numStr(ch chan string){
//	strABC := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
//	i := 0
//str := ""
//for{
//	i++
//	if strABC[i:i+1]=="Z"{
//		chFlag<-true
//		return
//	} else{
//
//		chFlag<-false
//	}
//str = <-ch
//ch<-(str +  strABC[i:i+1])
//}
//}
